<?php /* УТФ-8:fix */

class SPIcore__util
{
    public function get_user_ip()
    {
        return $_SERVER['REMOTE_ADDR'];
    }

    public function get_microtime()
    {
        list( $usec, $sec ) = explode(' ', microtime() );

        return (float) $sec + (float) $usec;
    }

    function string_to_translit( $string, $string_charset = 'UTF-8', $replacer_char = null, $allow_chars = null )
    {
        if( strtoupper( $string_charset ) != 'WINDOWS-1251' )
        {
            $string = iconv( $string_charset, 'WINDOWS-1251', $string );
        }

        $string = strtr(
            $string,
            array (
                chr(192) => 'A',    chr(193) => 'B',    chr(194) => 'V',    chr(195) => 'G',
                chr(196) => 'D',    chr(197) => 'E',    chr(168) => 'E', // e:
                chr(198) => 'ZH',   chr(199) => 'Z',    chr(200) => 'I',    chr(201) => 'Y',
                chr(202) => 'K',    chr(203) => 'L',    chr(204) => 'M',    chr(205) => 'N',
                chr(206) => 'O',    chr(207) => 'P',    chr(208) => 'R',    chr(209) => 'S',
                chr(210) => 'T',    chr(211) => 'U',    chr(212) => 'F',    chr(213) => 'H',
                chr(214) => 'TS',   chr(215) => 'CH',   chr(216) => 'SH',   chr(217) => 'SHCH',
                chr(218) => "'",   // tvordiy znak
                chr(219) => 'I',
                chr(220) => '',    // myagkiy znak
                chr(221) => 'E',    chr(222) => 'YU',   chr(223) => 'YA',

                chr(224) => 'a',    chr(225) => 'b',    chr(226) => 'v',    chr(227) => 'g',
                chr(228) => 'd',    chr(229) => 'e',    chr(184) => 'e', // E:
                chr(230) => 'zh',   chr(231) => 'z',    chr(232) => 'i',    chr(233) => 'y',
                chr(234) => 'k',    chr(235) => 'l',    chr(236) => 'm',    chr(237) => 'n',
                chr(238) => 'o',    chr(239) => 'p',    chr(240) => 'r',    chr(241) => 's',
                chr(242) => 't',    chr(243) => 'u',    chr(244) => 'f',    chr(245) => 'h',
                chr(246) => 'ts',   chr(247) => 'ch',   chr(248) => 'sh',   chr(249) => 'shch',
                chr(250) => "'",   // tvordiy znak
                chr(251) => 'i',
                chr(252) => '',    // myagkiy znak
                chr(253) => 'e',    chr(254) => 'yu',   chr(255) => 'ya',

                chr(170) => 'Ye',  // Ukr EEE
                chr(175) => 'Yi',  // Ukr I:
                chr(186) => 'ie',  // Ukr eee
                chr(191) => 'i',   // Ukr i:
            )
        );

        if( $replacer_char !== null )
        {
            $allow_chars = (string) $allow_chars;
            $string = preg_replace( '/[^0-9A-Za-z'.preg_quote($allow_chars).']/', $replacer_char, $string );

            if( $replacer_char && strlen( $replacer_char ) == 1 )
            {
                $string = preg_replace( '/'.preg_quote($replacer_char).'+/', $replacer_char, $string );
                $string = trim( $string, $replacer_char );
            }
        }

        return $string;
    }
}
